﻿// -----------------------------------------------------------------------
// <copyright file="IConnectionManager.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
// -----------------------------------------------------------------------
#region Usings

using System;
using System.Collections.Generic;

#endregion

namespace GateShift.Servers.GameServer.Managers.Connection
{
    /// <summary>
    /// Manager interface for connection managers
    /// </summary>
    public interface IConnectionManager : IManager
    {
        /// <summary>
        /// Event for handling clients after they have connected
        /// </summary>
        event EventHandler<ClientEventArgs> ClientConnected;

        /// <summary>
        /// Event for handling clients after they have disconnected
        /// </summary>
        event EventHandler<ClientEventArgs> ClientDisconnected;

        /// <summary>
        /// Event for handling clients after a packet has been released
        /// </summary>
        event EventHandler<ClientPacketEventArgs> ClientPacketRecieved;

        /// <summary>
        /// Sends data to the specified client by ID
        /// </summary>
        /// <param name="clientID">Client ID to send data to</param>
        /// <param name="packet">Packet to send to the client</param>
        void SendData(Guid clientID, ClientPacket packet);

        /// <summary>
        /// Disconnects the specified client
        /// </summary>
        /// <param name="clientID">Client ID to disconnect</param>
        void Disconnect(Guid clientID);

        /// <summary>
        /// Disconnects all clients
        /// </summary>
        void Disconnect();

        /// <summary>
        /// Checks to see if a client is currently connected
        /// </summary>
        /// <param name="clientID">Client ID to check</param>
        /// <returns>Whether or not the client is currently connected</returns>
        bool IsConnected(Guid clientID);

        /// <summary>
        /// Adds the specified object to the managed ServiceHost System
        /// </summary>
        /// <param name="key">Key used to identity the service</param>
        /// <param name="hostItem">object that contains the Contract</param>
        /// <exception cref="ArgumentNullException">Thrown if key or hostItem are null</exception>
        /// <exception cref="InvalidOperationException">Thrown if the key already exists</exception>
        void AddServiceHost(string key, object hostItem);

        /// <summary>
        /// Removes the specified key from the managed ServiceHost System
        /// </summary>
        /// <param name="key">Key used to identity the service</param>
        /// <exception cref="ArgumentNullException">Thrown if key is null</exception>
        /// <exception cref="KeyNotFoundException">Thrown if the key does not exist</exception>
        void RemoveServiceHost(string key);

        /// <summary>
        /// Opens a service channel for communicating of <typeparamref name="T" />
        /// </summary>
        /// <typeparam name="T">Service Interface to create the channel for</typeparam>
        /// <returns>Service channel created of <typeparamref name="T" /></returns>
        T OpenServiceChannel<T>();

        /// <summary>
        /// Closes a service channel of <typeparamref name="T" /> that was previously opened
        /// </summary>
        /// <param name="channel">A <typeparamref name="T" /> based channel to close</param>
        /// <typeparam name="T">Service Interface to create the channel for</typeparam>
        void CloseServiceChannel<T>(T channel);
    }
}